package edu.ynu.se.xiecheng.achitectureclass.entity;

import edu.ynu.se.xiecheng.achitectureclass.common.entity.LogicEntity;
import lombok.Data;
import lombok.ToString;
import org.hibernate.annotations.CreationTimestamp;
import javax.persistence.*;
import java.util.Date;
import java.util.List;

@Data
@Entity
@Table(name = "greenhouse")
@ToString(exclude = {"devices"})
public class GreenHouse extends LogicEntity {
    @Column(name = "box_no", nullable = false, unique = true)
    private String boxNo;

    @Column(nullable = false)
    private String name;

    private String address;

    @Column(nullable = false)
    private Double area;

    @Column(name = "create_time", nullable = false)
    @CreationTimestamp
    private Date createTime;

    @OneToMany(mappedBy = "greenhouse", cascade = CascadeType.ALL)
    private List<Device> devices;

    public int getDeviceCount() {
        return devices != null ? devices.size() : 0;
    }
}
